package com.ziyun.pop.rest.module.consult;

import com.service.common.model.PageParamDto;
import com.service.common.model.PageResult;
import com.service.ucenter.api.UserConsultService;
import com.service.ucenter.constant.UcenterResult;
import com.service.ucenter.exception.UserException;
import com.service.ucenter.model.consult.ConsultInfoVO;
import com.service.ucenter.model.consult.ConsultParam;
import com.service.ucenter.model.consult.ConsultVO;
import com.ziyun.pop.common.utils.UserUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(value = "ConsultRestApi", tags = "小程序咨询")
@RestController
@RequestMapping("popApi/consult")
public class ConsultRestApi {
    @Autowired
    private UserConsultService userConsultService;

    @ApiOperation(value = "查看店铺的咨询")
    @ApiResponses({ @ApiResponse(code = 200, message = "查看我的消息成功", response = ConsultVO.class) })
    @PostMapping("/sellerMessageList")
    public UcenterResult<PageResult<ConsultVO>> sellerMessageList(@RequestBody PageParamDto pageParamDto){
        Long sellerId=UserUtils.getCurentUser().getSellerId();
        return userConsultService.sellerMessageList(pageParamDto.getPageNo(),pageParamDto.getPageSize(), sellerId);
    }

    @ApiOperation(value = "聊天信息详情")
    @ApiResponses({ @ApiResponse(code = 200, message = "查看我的消息成功", response = ConsultInfoVO.class) })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "pageNo", value = "当前页", required = true, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页数", required = true, paramType = "query", dataType = "Integer")
    })
    @GetMapping("/loadConsultInfo")
    public  UcenterResult<PageResult<ConsultInfoVO>> loadConsultInfo(Long userId,Integer pageNo,Integer pageSize ){
        Long sellerId=UserUtils.getCurentUser().getSellerId();
        return userConsultService.loadConsultInfo(pageNo,pageSize, sellerId,userId);
    }

    @ApiOperation(value = "回复客户消息")
    @PostMapping("/sellerSendMsg")
    public  UcenterResult<?> sellerSendMsg(@RequestBody ConsultParam consultParam){
        Long sellerId=UserUtils.getCurentUser().getSellerId();
        consultParam.setSellerId(sellerId);
        return userConsultService.sellerSendMsg(consultParam);
    }

    @ApiOperation(value = "获取用户留言商户最新formId")
    @ApiResponses({ @ApiResponse(code = 200, message = "获取用户留言商户最新formId") })
    @GetMapping("/getUserFormId")
    public   UcenterResult<Map> getUserFormId(@RequestParam("userId") Long userId ){
        Long sellerId=UserUtils.getCurentUser().getSellerId();
        return userConsultService.getUserFormId(userId, sellerId);
    }
}
